package com.nali.dal.mongo.dao.general;

import org.apache.log4j.Logger;

import com.mongodb.MongoException.DuplicateKey;
import com.mongodb.MongoException.Network;
import com.nali.dal.exception.DalRuntimeException;
import com.nali.dal.exception.NetworkException;
import com.nali.dal.exception.UniqueKeyException;
import com.nali.dal.exception.UnknownException;

public class ExceptionTraner {
	private static Logger logger = Logger.getLogger(ExceptionTraner.class);

	public static DalRuntimeException tranException(Exception e) {
		logger.error(e.getMessage(), e);
		if (e instanceof DuplicateKey) {
			return new UniqueKeyException(e.getMessage());
		}
		if (e instanceof Network) {
			return new NetworkException(e.getMessage());
		}
		return new UnknownException(e.getMessage());
	}
}
